import dt from '@dt/dt'
import Opt from '@/components/dt/info/Opt.js'
import houseOpt from '@/biz/option/house.js'
import nameOpt from '@/biz/option/name.js'
import organizationOpt from '@/biz/option/organization.js'
import ruleOpt from '@/biz/option/rule.js'

class SearchOpt extends Opt {

  constructor(info) {
    super(info)
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    let monthRange = {
      title: '奖金月份',
      placeholder: '请选择',
      key: 'bonusStartMonth',
      col: 5,
      dtTime: {
        dateType: 'month',
        dateFormat: 'YYYY-MM',
        clearable: true
      },
      data: {
        from: (info) => {
          if (info.bonusStartMonth || info.bonusEndMonth) {
            return [info.bonusStartMonth, info.bonusEndMonth]
          }
          return null
        },
        to: (val) => {
          return {
            bonusStartMonth: val[0],
            bonusEndMonth: val[1]
          }
        }
      },
      rules: [
        ruleOpt.check('请选择奖金月份范围', (val) => {
          return !val ^ !this.info.bonusEndMonth
        }, 'change')
      ]
    }

    this.all = [
      organizationOpt.create({
        key: 'orgIds'
      }),
      houseOpt.create({
        to: (info) => {
          return {
            housesId: info.housesId
          }
        }
      }),
      monthRange,
      nameOpt.createPeople({
        key: 'userId',
        validate: 3,
        title: '工号/姓名',
        to: (info) => {
          return {
            userId: info.userId
          }
        }
      })
    ]
  }
}

export default SearchOpt